package org.flyby.component;

import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.internal.HtmlHeaderContainer;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.flyby.FlybyResourcePackage;

public class FlybyPage extends WebPage {

    private FeedbackPanel feedback;

    public FlybyPage() {
        super();
        init();
    }

    public FlybyPage(IModel<?> model) {
        super(model);
        init();
    }

    public FlybyPage(PageParameters parameters) {
        super(parameters);
        init();
    }

    @Override
    public void renderHead(HtmlHeaderContainer container) {
        super.renderHead(container);
        container.getHeaderResponse().render(OnDomReadyHeaderItem.forScript("$('#" + this.getMarkupId() + "').appendTo( '.ui-page' ).trigger( 'create' )"));
    }

    private void init() {
        add(new FlybyResourcePackage());
        feedback = new FeedbackPanel("feedback");
        feedback.setOutputMarkupId(true);
        add(feedback);
    }

    public FeedbackPanel getFeedbackPanel() {
        return feedback;
    }
}
